package top.xiaoshuaila.moments.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.xiaoshuaila.moments.pojo.RespBean;
import top.xiaoshuaila.moments.pojo.Users;
import top.xiaoshuaila.moments.service.MessageService;
import top.xiaoshuaila.moments.utils.Usersutils;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("message")
@Api(tags = "消息通知接口")
public class MessageController {
    @Autowired
    private MessageService messageService;
    @GetMapping("getmes")
    @ResponseBody
    @ApiOperation("获取消息列表")
    public RespBean getmes(int page){
        Users users= Usersutils.getuser();
        return messageService.getmes(users.getId(),page);
    }
    @PutMapping("clearmes")
    @ResponseBody
    @ApiOperation("清除未读消息")
    public RespBean clearmes(){
        Users users= Usersutils.getuser();
        return messageService.clearmes(users.getId());
    }
    @GetMapping("gettotal")
    @ResponseBody
    @ApiOperation("获取消息列表总数")
    public RespBean gettotal(){
        Users users= Usersutils.getuser();
        return RespBean.success("success",messageService.gettotal(users.getId())) ;
    }
}
